package com.njym.java.security.admin.rest;


import com.njym.java.security.admin.biz.UserTeacherMessageBiz;
import com.njym.java.security.admin.entity.UserTeacherMessage;
import com.njym.java.security.common.msg.ObjectRestResponse;
import com.njym.java.security.common.rest.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("userTeacherMessage")
public class UserTeacherMessageController extends BaseController<UserTeacherMessageBiz,UserTeacherMessage> {
    /**
     * 查询历史记录
     * @param from
     * @param to
     * @param limit
     * @param page
     * @return
     */
    @RequestMapping(value = "/queryTeacherHistory",method = RequestMethod.GET)
    @ResponseBody
    public ObjectRestResponse<UserTeacherMessage> queryTeacherHistory(String from, String to,
        @RequestParam(defaultValue = "10") int limit, @RequestParam(defaultValue = "1")int page){

        List<UserTeacherMessage> list = baseBiz.queryTeacherHistory(from + to, to + from, page, limit);
        int total = baseBiz.countTeacherHistory(from + to, to + from);
        int totalPages = (int) Math.ceil((double) total / limit);

        Map<String, Object> data = new HashMap<>(2);
        data.put("list", list);
        data.put("totalPages", totalPages);
        return new ObjectRestResponse<UserTeacherMessage>().rel(true).data(data);

    }
}